package io.lkt.modules.sys.service.impl;

import io.lkt.modules.sys.dao.BUserInfoDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.lkt.common.utils.PageUtils;
import io.lkt.common.utils.Query;

import io.lkt.modules.sys.dao.BUserGroupOpenidDao;
import io.lkt.modules.sys.entity.BUserGroupOpenidEntity;
import io.lkt.modules.sys.service.BUserGroupOpenidService;


@Service("bUserGroupOpenidService")
public class BUserGroupOpenidServiceImpl extends ServiceImpl<BUserGroupOpenidDao, BUserGroupOpenidEntity> implements BUserGroupOpenidService {
    @Autowired
    private BUserInfoDao bUserInfoDao;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<BUserGroupOpenidEntity> page = this.page(
                new Query<BUserGroupOpenidEntity>().getPage(params),
                new QueryWrapper<BUserGroupOpenidEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public Integer getUserOtherFollowGzh(Integer userId) {
        Integer total = null;
        Map<String, Object> params = new HashMap<>();
        //BUserGroupOpenidEntity entity = bUserInfoDao.getMainUserId(userId);
        String unionId= bUserInfoDao.getUnionId(userId);

        if (unionId != null && !unionId.equals("")) {
            //params.put("mainUserId", entity.getUserId());
            params.put("unionId", unionId);
            total = bUserInfoDao.getUserOtherFollowGzhTotal(params);
        }
        return total;
    }

    @Override
    public BUserGroupOpenidEntity getUserOpenId(String gzhCode, Integer userId) {
        return baseMapper.getUserOpenId(gzhCode, userId);
    }
}
